/*
 * Base class for JPhys shapes
 */
#ifndef _JPHYSOBJECT_H_
#define _JPHYSOBJECT_H_

#include "JPVec3.h"

class JPhysCollisionCBHandler 
{
public:

	virtual void enteredCollision() const	= 0;
	virtual void persistCollision() const	= 0;
	virtual void exitedCollision() const	= 0;
};

class JPhysObject
{
public:

	JPhysObject():m_mass(0.0f),m_isSolid(false),m_isRigid(false), m_collisionCBHandler(0){}

	//---------------------------------------------------
	// JPhysObject virtuals
	//---------------------------------------------------

	virtual void update(float deltaSeconds);

	/*
	 * Compute's the objects dimensions aligned to the world axis
	 */
	virtual void computeAABBLengths() = 0;

	//---------------------------------------------------
	// Public API
	//---------------------------------------------------

	void setHandler(JPhysCollisionCBHandler *cbHandler) { m_collisionCBHandler = cbHandler; }
	const JPhysCollisionCBHandler *getCBHandler() const { return m_collisionCBHandler; }

	/*
	 *	Non solid's have no intersection correction
	 *	Non solid bodies cannot be rigid
	 */
	void setSolid(bool value)	{ m_isSolid = value; if(!value) m_isRigid = false; }
	bool isSolid() const		{ return m_isSolid; }

	/*
	 * Set's the object as a rigid body
	 * rigid bodies are always solid
	 */
	void setRigid(bool value)	{ m_isRigid = value; if(value) m_isSolid = true; }
	bool isRigid() const		{ return m_isRigid; }

	/*
	 * Bunch of get/sets for the body properties
	 */
	void setMass(float m)	{ m_mass = m; }
	float mass() const		{ return m_mass; }

	void setIntertia(const JPVec3 &vi)	{ m_intertia = vi; }
	const JPVec3 &intertia() const		{ return m_intertia; }

	void setLinearVel(const JPVec3 &v)	{ m_linearVelocity = v; }
	const JPVec3 &linearVel() const		{ return m_linearVelocity; }

	void setAngularVel(const JPVec3 &v) { m_angularVelocity = v; }
	const JPVec3 &angularVel() const	{ return m_angularVelocity; }

	void setPosition(const JPVec3 &p)	{ m_position = p; }
	const JPVec3 &position() const		{ return m_position; }

private:

	// body params
	float	m_mass;
	JPVec3	m_intertia;
	JPVec3	m_linearVelocity;
	JPVec3	m_angularVelocity;

	JPVec3	m_position;
	// half extents along the world axis
	JPVec3	m_AABBe;

	bool m_isSolid;
	bool m_isRigid;

	const JPhysCollisionCBHandler *m_collisionCBHandler;
};

#endif //_JPHYSOBJECT_H_